package com.company.vmpx.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.LayoutRes;

import com.dee.components.widget.verticalview.SimpleViewHolder;
import com.company.vmpx.R;

public class ButtomDialogView extends Dialog {

    private boolean isCancelable =true;//控制点击dialog外部是否dismiss
    private boolean isBackCancelable =true;//控制返回键是否dismiss
    private View view;
    private Context context;

    //这里的view其实可以替换直接传layout过来的 因为各种原因没传(lan)
    public ButtomDialogView(Context context, @LayoutRes int resource) {
        super(context, R.style.MyDialog);
        this.context = context;
        this.view = LayoutInflater.from(context).inflate(resource, null);
    }

    public void setMViewHolder(ViewHolder mViewHolder) {
        SimpleViewHolder viewHolder = new SimpleViewHolder(view);
        if (mViewHolder != null) {
            mViewHolder.onHolder(viewHolder);
        }
    }

    public void setIscancelable(boolean cancelable) {
        isCancelable = cancelable;
    }

    public void setBackCancelable(boolean backCancelable) {
        isBackCancelable = backCancelable;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(view);//这行一定要写在前面
        setCancelable(isCancelable);//点击外部不可dismiss
        setCanceledOnTouchOutside(isBackCancelable);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
    }

}
